package likou.offer;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/8/12  22:14
 */
public class _18 {
    class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public ListNode deleteNode(ListNode head, int val) {
        while (head.val == val && head != null) {
            head = head.next;
        }
        ListNode res = head;
        while (head.next != null) {
            if (head.next.val == val) {
                head.next = head.next.next;
            } else {
                head = head.next;
            }
        }
        return res;
    }

}
